import com.alibaba.excel.EasyExcel;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.io.File;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * @author hjc-YYDS
 * @date 2024/3/4 15:23
 */
@Slf4j
public class MyTest01 {
    @Test
    public void testFileRead() {
        File file = new File("D:\\D24_Resource\\user-list.xlsx");
        List<Object> list = EasyExcel.read(file).sheet(0).doReadSync();

        for (Object item : list) {
            //System.out.println(item);
            //log.info("item:{} {}",item.getClass(),item);
            log.info("item:{}", item);
        }

        List<Map<Integer, Object>> list2 = EasyExcel.read(file).sheet(0).headRowNumber(2).doReadSync();
        for (Map<Integer, Object> item : list2) {
            log.info("昵称:{}，性别：{}", item.get(0), item.get(1));
        }
    }


    @Test
    public void testInputRead() {
        InputStream stream = MyTest01.class.getClassLoader().getResourceAsStream("user-list.xlsx");
        List<Object> list = EasyExcel.read(stream).sheet(0).doReadSync();
        for (Object item : list) {
            log.info("item:{}", item);
        }
    }

    @Test
    public void testInputModelRead() {
        InputStream stream = MyTest01.class.getClassLoader().getResourceAsStream("user-list.xlsx");
        List<User> list = EasyExcel.read(stream).sheet(0).head(User.class).doReadSync();
        for (User item : list) {
            log.info("昵称:{}，性别：{}，生日：{}，分数：{}，邮箱：{}", item.getName(),
                    item.getGender(), item.getBirthday(), item.getScore(), item.getEmail());
        }
    }

    @Test
    public void testRead003() {
        InputStream stream = MyTest01.class.getClassLoader().getResourceAsStream("user-list.xlsx");
        List<User> list = EasyExcel.read(stream).sheet(0).head(User.class).headRowNumber(2).doReadSync();
        for (User item : list) {
            log.info("昵称:{}，性别：{}，生日：{}，分数：{}，邮箱：{}", item.getName(),
                    item.getGender(), item.getBirthday(), item.getScore(), item.getEmail());
            //System.out.println(item);
        }
    }

}
